#include "./Server_code/TcpServer.hpp"
#define DEFAULT_PORT 8500


void OnMessage(const PtrConnection &pc, Buffer *msg){
    log_message(DEBUG, "%s", msg->ReadPosition());
    msg->MoveReadOffset(msg->ReadAbleSize());
    std::string str("I am server");
    pc->Send(str.c_str(), str.size());
}

void ConnecitonClose(const PtrConnection &pc){
    //log_message(DEBUG, "连接关闭");
}

void Onconnected(const PtrConnection &pc){
    log_message(DEBUG, "建立了一个新连接，地址为%p", (void*)pc.get());
}



int main(){
    TcpServer server(DEFAULT_PORT);
    server.SetThreadCount(20);
    server.SetConnectedCallback(std::bind(Onconnected, std::placeholders::_1));
    server.SetMessageCallback(std::bind(OnMessage, std::placeholders::_1, std::placeholders::_2));
    server.SetClosedCallback(std::bind(ConnecitonClose, std::placeholders::_1));
    server.EnableInactiveRelease(10);
    server.Start();
    return  0;
}
